home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Draw Editor / Source / DrawEditorUtils.cpp < prev    next >
Encoding:
Text File  |  1995-12-11  |  24.6 KB  |  944 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        DrawEditorUtils.cpp
  3.  
  4.     Contains:    DrawEditor utility functions & classes
  5.  
  6.     Written by:    Adapted from SamplePartUtils.cpp and enhanced by Dave Stafford.
  7.  
  8.     Copyright:    © 1994,95 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11. // --- DrawEditor Includes ---
  12.  
  13. #ifndef _DRAWEDITORUTILS_
  14. #include "DrawEditorUtils.h"
  15. #endif
  16.  
  17. #ifndef _DRAWEDITORGLOBALS_
  18. #include "DrawEditorGlobals.h"
  19. #endif
  20.  
  21. #ifndef _DRAWEDITORCONSTANTS_
  22. #include "DrawEditorConstants.h"
  23. #endif
  24.  
  25. #ifndef _DRAWEDITORDEF_
  26. #include "DrawEditorDef.h"
  27. #endif
  28.  
  29. #ifndef _SHAPES_
  30. #include "Shapes.h"
  31. #endif
  32.  
  33. #ifndef _PROMISE_
  34. #include "Promise.h"
  35. #endif
  36.  
  37. // --- OpenDoc Includes ---
  38.  
  39. #ifndef SOM_ODClipboard_xh
  40. #include <Clipbd.xh>
  41. #endif
  42.  
  43.  
  44. #ifndef _FOCUSLIB_
  45. #include "FocusLib.h"
  46. #endif
  47.  
  48. #ifndef _ODTYPES_
  49. #include <ODTypes.h>
  50. #endif
  51.  
  52. #ifndef SOM_ODPart_xh
  53. #include <Part.xh>
  54. #endif
  55.  
  56. #ifndef SOM_Module_OpenDoc_StdProps_defined
  57. #include <StdProps.xh>
  58. #endif
  59.  
  60. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  61. #include <StdTypes.xh>
  62. #endif
  63.  
  64. #ifndef SOM_ODFrame_xh
  65. #include <Frame.xh>
  66. #endif
  67.  
  68. #ifndef SOM_ODFrameFacetIterator_xh
  69. #include <FrFaItr.xh>
  70. #endif
  71.  
  72. #ifndef SOM_ODCanvas_xh
  73. #include <Canvas.xh>
  74. #endif
  75.  
  76. #ifndef SOM_ODTransform_xh
  77. #include <Trnsform.xh>
  78. #endif
  79.  
  80. #ifndef SOM_ODStorageUnit_xh
  81. #include <StorageU.xh>
  82. #endif
  83.  
  84. #ifndef SOM_ODNameSpaceManager_xh
  85. #include <NmSpcMg.xh>
  86. #endif
  87.  
  88. // -- OpenDoc Utilities --
  89.  
  90. #ifndef _TEMPOBJ_
  91. #include "TempObj.h"
  92. #endif
  93.  
  94. #ifndef _TEMPITER_
  95. #include "TempIter.h"
  96. #endif
  97.  
  98. #ifndef _ODUTILS_
  99. #include "ODUtils.h"
  100. #endif
  101.  
  102. #ifndef _EXCEPT_
  103. #include "Except.h"
  104. #endif
  105.  
  106. #ifndef _ISOSTR_
  107. #include "ISOStr.h"
  108. #endif
  109.  
  110. #ifndef SOM_ODDragAndDrop_xh
  111. #include <DragDrp.xh>
  112. #endif
  113.  
  114. #ifndef _ODMEMORY_
  115. #include "ODMemory.h"
  116. #endif
  117.  
  118. #ifndef _PASCLSTR_
  119. #include "PasclStr.h"
  120. #endif
  121.  
  122. #ifndef _STORUTIL_    
  123. #include "StorUtil.h"
  124. #endif
  125.  
  126. #ifndef _STDTYPIO_
  127. #include "StdTypIO.h"
  128. #endif
  129.  
  130. #ifndef _USERSRCM_
  131. #include "UseRsrcM.h"
  132. #endif
  133.  
  134. // --- Macintosh Includes ---
  135.  
  136. #ifndef __RESOURCES__
  137. #include <Resources.h>
  138. #endif
  139.  
  140. #ifndef __DIALOGS__
  141. #include <Dialogs.h>
  142. #endif
  143.  
  144. #ifndef __WINDOWS__
  145. #include <Windows.h>
  146. #endif
  147.  
  148. #ifndef __TOOLUTILS__
  149. #include <ToolUtils.h>
  150. #endif
  151.  
  152. #ifndef mathRoutinesIncludes
  153. #include <math routines.h>
  154. #endif
  155.  
  156. #ifndef __SCRIPT__
  157. #include <Script.h>
  158. #endif
  159.  
  160. #ifndef _STDLIB
  161. #include <StdLib.h>
  162. #endif
  163.  
  164. #pragma segment DrawEditorUtilities
  165.  
  166.  
  167. //====================================================================
  168. // Utility Functions
  169. //====================================================================
  170.  
  171. //------------------------------------------------------------------------------
  172. // DrawEditor Specific Utilities
  173. //------------------------------------------------------------------------------
  174.  
  175. //--------------------------------------------------------------------
  176. // HiliteFacet
  177. //--------------------------------------------------------------------
  178. void HiliteFacet( Environment* ev, ODDragAndDrop* dad, 
  179.                                 ODFacet* facet, ODBoolean show)
  180. {
  181.     CFocus forDrawing(ev, facet);
  182.     
  183.     ODFrame*    displayFrame = facet->GetFrame(ev);
  184.     ODShape*    frameShape = displayFrame->AcquireFrameShape(ev, kODNULL);
  185.     RgnHandle    bRgn = frameShape->GetQDRegion(ev);
  186.     
  187.     // Release acquired geometry
  188.     ODReleaseObject(ev, frameShape);
  189.  
  190.     if (show)
  191.         ShowDragHilite(dad->GetDragReference(ev), bRgn, true);
  192.     else
  193.         HideDragHilite(dad->GetDragReference(ev));
  194. }
  195.  
  196. //--------------------------------------------------------------------
  197. // MapRect
  198. //--------------------------------------------------------------------
  199. void MapRect( Rect& baseRect, Rect& resizeRect, Rect* result )
  200. {
  201.     
  202.     ODSShort ratio = (result->right - result->left) / (baseRect.right - baseRect.left);
  203.     
  204.     // Ration can't be 0
  205.     if (ratio==0)
  206.         ratio = 1;
  207.     
  208.     result->left += (resizeRect.left - baseRect.left) * ratio;
  209.     result->right += (resizeRect.right - baseRect.right) * ratio;
  210.     
  211.     ratio = (result->bottom - result->top) / (baseRect.bottom - baseRect.top);
  212.     
  213.     // Ration can't be 0
  214.     if (ratio==0)
  215.         ratio = 1;
  216.     
  217.     result->top += (resizeRect.top - baseRect.top) * ratio;
  218.     result->bottom += (resizeRect.bottom - baseRect.bottom) * ratio;
  219. }
  220.  
  221. //--------------------------------------------------------------------
  222. // SortRect
  223. //--------------------------------------------------------------------
  224. void SortRect( Rect* rect )
  225. {
  226.     if (rect->left > rect->right)
  227.     {
  228.         ODSShort temp = rect->left;
  229.         rect->left = rect->right;
  230.         rect->right = temp;
  231.     }
  232.     if (rect->top > rect->bottom)
  233.     {
  234.         ODSShort temp = rect->top;
  235.         rect->top = rect->bottom;
  236.         rect->bottom = temp;
  237.     }
  238. }
  239.  
  240. //--------------------------------------------------------------------
  241. // ValidRect
  242. //--------------------------------------------------------------------
  243. ODBoolean IsValidRect( Rect& rect )
  244. {
  245.     return (rect.right>=rect.left && rect.bottom>=rect.top);
  246. }
  247.  
  248. //--------------------------------------------------------------------
  249. // StrToShort
  250. //--------------------------------------------------------------------
  251. ODSShort StrToShort( StringPtr pstr )
  252. {
  253.     // Throw if we get a bad parameter
  254.     THROW_IF_NULL(pstr);
  255.     
  256.     // Allocate temp str
  257.     // Throw if we don't get an allocation
  258.     char* cstr = (char*)::ODNewPtr((ODUByte)pstr[0]);
  259.     THROW_IF_NULL(cstr);
  260.     
  261.     // convert to cstr
  262.     ODSByte size = pstr[0]; 
  263.     memcpy(cstr, pstr+1, size);
  264.     cstr[size+1] = 0L;
  265.     
  266.     // convert to integer
  267.     return atoi(cstr);
  268. }
  269.  
  270. //--------------------------------------------------------------------
  271. // NumToString
  272. //--------------------------------------------------------------------
  273. void NumToString( ODSShort number, char* result )
  274. {
  275.     ODULong    i = 0;
  276.     ODULong    num = number;
  277.     
  278.     do {
  279.         result[i] = (ODSByte) (num % 10 + '0');
  280.         if (result[i] > '9') DebugStr("\pError in NumToString");
  281.         i++;
  282.     } while ((num /= 10) > 0);
  283.     result[i] = '\0';
  284.  
  285.     ODSByte    c;
  286.     ODULong    j;
  287.     
  288.     for (i = 0, j = strlen(result)-1; i < j;i++, j--) {
  289.         c = result[i];
  290.         result[i] = result[j];
  291.         result[j] = c;
  292.     }
  293.     c2pstr(result);
  294. }
  295.  
  296. //--------------------------------------------------------------------
  297. // RectContainsRect
  298. //--------------------------------------------------------------------
  299. ODBoolean RectContainsRect(Rect& rect, Rect& inside)
  300. {
  301.     Rect tRect = rect;
  302.     Rect containsRect = inside;
  303.     
  304.     // Ensure similar co-ods
  305.     OffsetRect(&tRect, -tRect.left, -tRect.top);
  306.     OffsetRect(&containsRect, -containsRect.left, -containsRect.top);
  307.     
  308.     return (tRect.bottom <= containsRect.bottom && tRect.right < containsRect.right);
  309. }
  310.  
  311. //--------------------------------------------------------------------
  312. // InspectShape
  313. //--------------------------------------------------------------------
  314. void ChangeFacetHighlight(Environment* ev, 
  315.                             ODFacet* changeFacet, 
  316.                             ODHighlight newHighlight)
  317. {
  318.     // Notify the facet of the change
  319.     changeFacet->ChangeHighlight(ev, newHighlight);
  320.     
  321.     // Invalidate the frame to redraw the changed facet
  322.     ODFrame* tFrame = changeFacet->GetFrame(ev);
  323.     tFrame->Invalidate(ev, kODNULL, kODNULL);
  324. }
  325. //--------------------------------------------------------------------
  326. // InspectShape
  327. //--------------------------------------------------------------------
  328. void InspectShape( Environment* ev, ODShape* shape )
  329. {
  330.     RgnHandle shapeRgn = (shape->GetQDRegion(ev));
  331.     Rect shapeRect = (**shapeRgn).rgnBBox;
  332.     
  333.     ODSShort top = shapeRect.top;
  334.     ODSShort left = shapeRect.left;
  335.     ODSShort bottom = shapeRect.bottom;
  336.     ODSShort right = shapeRect.right;
  337.     
  338.     DebugStr("\pInspect Shape.");
  339. }
  340. //--------------------------------------------------------------------
  341. // SetMenuItemText
  342. //--------------------------------------------------------------------
  343. void SetMenuItemText( Environment* ev, ODID command, ODID cmdTextID )
  344. {
  345.     Str63            text;
  346.     ODIText*        menuItem = kODNULL;
  347.     
  348.     ODSLong tRef;
  349.     tRef = BeginUsingLibraryResources();
  350.     
  351.     TRY
  352.     
  353.         // Load the command text from the menu strings list resource
  354.         GetIndString(text, kMenuStringResID, cmdTextID);
  355.         
  356.         // Create the itext string
  357.         menuItem = CreateIText(gGlobals->fEditorsScript, gGlobals->fEditorsLanguage, (StringPtr)&text);
  358.         
  359.         // Change the menu item
  360.         if ( menuItem )
  361.             gGlobals->fMenuBar->SetItemString(ev, command, menuItem);
  362.             
  363.         // Dispose the menu text, since the menu bar makes a copy
  364.         DisposeIText(menuItem);
  365.     
  366.     CATCH_ALL
  367.         DebugStr("\pSetMenuItemText Failed.");
  368.     ENDTRY;
  369.     
  370.     EndUsingLibraryResources(tRef);
  371.  
  372. }
  373.  
  374. //--------------------------------------------------------------------
  375. // ValueOnClipboard
  376. //--------------------------------------------------------------------
  377.  
  378. ODBoolean ValueOnClipboard(Environment *ev, ODValueType type, ODSession* session)
  379. {
  380.     ODBoolean        result = kODFalse;
  381.     ODClipboard*    clipboard = session->GetClipboard(ev);
  382.  
  383.     TRY
  384.         ODStorageUnit* su = clipboard->GetContentStorageUnit(ev);
  385.         result = su->Exists(ev, kODPropContents, type, 0);
  386.     CATCH_ALL
  387.     ENDTRY
  388.  
  389.     return result;
  390. }
  391.  
  392. //--------------------------------------------------------------------
  393. // CheckAndResolvePromisedShapes
  394. //
  395. // Iterate over the given list of shapes. If any of them are promised 
  396. // then fulfill the promise on the clipboard.
  397. //--------------------------------------------------------------------
  398.  
  399. void CheckAndResolvePromisedShapes(Environment *ev, 
  400.                                     COrderedList* shapeList, 
  401.                                     ODSession* session)
  402. {
  403.     // Before removing / deleting shapes check to see if they
  404.     // are promised to the clipboard.
  405.     COrdListIterator iter(shapeList);
  406.     
  407.     // We only need to do the resolve for one promised shape.
  408.     ODBoolean foundPromisedShape = kODFalse;
  409.     for (CShape* shape = (CShape*)iter.First();
  410.         iter.IsNotComplete()&&!foundPromisedShape; 
  411.         shape = (CShape*)iter.Next())
  412.     {
  413.         if (shape->IsPromisedToClipboard())
  414.             ::ResolveClipboardPromises(ev, session);
  415.         return;
  416.     }
  417. }
  418.  
  419. //--------------------------------------------------------------------
  420. // LoadTempMemPicture
  421. //--------------------------------------------------------------------
  422.  
  423. PicHandle ODLoadPicture(ODSShort id)
  424. {
  425.     TRY
  426.         return (PicHandle)(::ODReadResource( 'PICT', id ));
  427.     CATCH_ALL
  428.     #ifdef ODDebug
  429.         DebugStr("\pLoad of picture Failed.");
  430.     #endif
  431.     ENDTRY
  432.     
  433.     return kODNULL;
  434. }
  435.  
  436.  
  437. //--------------------------------------------------------------------
  438. // DeletePicture
  439. //--------------------------------------------------------------------
  440.  
  441. void ODDeletePicture(PicHandle thePict)
  442. {
  443.     ::ODDisposeHandle((ODHandle)thePict);
  444. }
  445.  
  446.  
  447.  
  448. //--------------------------------------------------------------------
  449. // ResolveClipboardPromises
  450. //--------------------------------------------------------------------
  451.  
  452. void ResolveClipboardPromises(Environment *ev, ODSession* session)
  453. {
  454.     ODClipboard*    clipboard = session->GetClipboard(ev);
  455.  
  456.     TRY
  457.     
  458.     if (gGlobals->fClipboardPromise)
  459.     {
  460.         if (clipboard->GetUpdateID(ev) == gGlobals->fClipboardPromise->GetUpdateID())
  461.         {
  462.             ODStorageUnit* su = clipboard->GetContentStorageUnit(ev);
  463.             su->ResolveAllPromises(ev);
  464.         }
  465.         else
  466.         {
  467.             // Mark shapes as promised to the clipboard
  468.              gGlobals->fClipboardPromise->ShapesPromisedToClipboard(ev, kODFalse);
  469.             
  470.             delete gGlobals->fClipboardPromise;
  471.             gGlobals->fClipboardPromise = kODNULL;
  472.         }
  473.     }
  474.     
  475.     CATCH_ALL
  476.     ENDTRY
  477. }
  478.  
  479. //=========================================================================
  480. // StorageUnit I/O
  481. //=========================================================================
  482.  
  483. //-------------------------------------------------------------------------
  484. // StorageUnitSetISOStrValue -- Write out string length and string to currently focused stream
  485. //-------------------------------------------------------------------------
  486.  
  487. void        StorageUnitSetISOStrValue(    ODStorageUnit* su,
  488.                                         Environment* ev, 
  489.                                         ODISOStr value)
  490. {
  491.     ODULong size = strlen(value)+1;
  492.     StorageUnitSetValue(su, ev, sizeof(ODULong), &size);
  493.     StorageUnitSetValue(su, ev, size, (ODValue)value);
  494. }
  495.  
  496. //-------------------------------------------------------------------------
  497. // StorageUnitGetISOStrValue -- Read in string length and string from currently focused stream
  498. // Allocate space for result.
  499. //-------------------------------------------------------------------------
  500.  
  501. ODISOStr    StorageUnitGetISOStrValue(     ODStorageUnit* su,
  502.                                         Environment* ev)
  503. {
  504.         ODULong size;
  505.         StorageUnitGetValue(su, ev, sizeof(ODULong), &size);
  506.         ODISOStr value = (ODISOStr)::ODNewPtr(size);
  507.         StorageUnitGetValue(su, ev, size, value);
  508.         
  509.         return value;
  510. }
  511.  
  512.  
  513. //--------------------------------------------------------------------
  514. // SetPartName
  515. //--------------------------------------------------------------------
  516.  
  517. void SetPartName(Environment* ev, ODPart* part, ODIText* partName)
  518. {
  519.     ODStorageUnit* storageUnit = part->GetStorageUnit(ev);
  520.     
  521.     if ( storageUnit->Exists(ev, kODPropName, kODMacIText, 0) )
  522.     {
  523.         // The fact that ODSetITextProp takes an ev parameter means it could fail
  524.         TRY
  525.         ODSetITextProp(ev, storageUnit, kODPropName, kODMacIText, partName);
  526.         CATCH_ALL
  527.         ENDTRY
  528.     }
  529. }
  530.  
  531. //--------------------------------------------------------------------
  532. // GetEditorScriptLanguage
  533. //--------------------------------------------------------------------
  534.  
  535. void GetEditorScriptLanguage(Environment* ev, ODScriptCode* script,
  536.                                         ODLangCode* language)
  537. {
  538.     typedef struct versResource {
  539.         // Not accurrate template, just used to get at the region code.
  540.         // (see Inside Mac: Toolbox Essentials 7-70)
  541.         long            versionNumberStuff;
  542.         unsigned short    regionCode;
  543.         Str255            versionNumberString;
  544.         Str255            versionMessageString;
  545.     } versResource, **versResourceHdl;
  546.     
  547.     OSErr    error = noErr;
  548.     long    region;
  549.     
  550.     ODSLong tRef;
  551.     tRef = BeginUsingLibraryResources();
  552.     {
  553.         Handle versHdl = GetResource('vers', 1);
  554.         
  555.         // Get the region code of the editor, otherwise use the
  556.         // region code the of the primary system script.
  557.         
  558.         if ( versHdl )
  559.         {
  560.             region = (long)(*(versResourceHdl)versHdl)->regionCode;
  561.             ReleaseResource(versHdl);
  562.         }
  563.         else
  564.         {
  565.             region = GetScriptManagerVariable(smRegionCode);
  566.         }
  567.         
  568.         // Spanish & Japanese are not actually supported by the editor.
  569.         // They are provided as examples of how to add recognition of
  570.         // additional regions (see Script.h for region codes).
  571.         
  572.         switch ((short)region) {
  573.             case verUS:
  574.                 *script = smRoman;
  575.                 *language = langEnglish;
  576.                 break;
  577.             case verSpain:
  578.                 *script = smRoman;
  579.                 *language = langSpanish;
  580.                 break;
  581.             case verJapan:
  582.                 *script = smJapanese;
  583.                 *language = langJapanese;
  584.                 break;
  585.             default:
  586.                 *script = smRoman;
  587.                 *language = langEnglish;
  588.         }                
  589.     }
  590.     EndUsingLibraryResources(tRef);
  591. }
  592.  
  593. //--------------------------------------------------------------------
  594. // FixedToIntRect
  595. //--------------------------------------------------------------------
  596.  
  597. void FixedToIntRect(ODRect& fixedRect, Rect& intRect)
  598. {
  599.     intRect.top        = FixedToInt(fixedRect.top);
  600.     intRect.left    = FixedToInt(fixedRect.left);
  601.     intRect.bottom    = FixedToInt(fixedRect.bottom);
  602.     intRect.right    = FixedToInt(fixedRect.right);
  603. }
  604.  
  605. //--------------------------------------------------------------------
  606. // IntToFixedRect
  607. //--------------------------------------------------------------------
  608.  
  609. void IntToFixedRect(Rect& intRect, ODRect& fixedRect)
  610. {
  611.     fixedRect.left        = ff(intRect.left);
  612.     fixedRect.top        = ff(intRect.top);
  613.     fixedRect.right        = ff(intRect.right);
  614.     fixedRect.bottom    = ff(intRect.bottom);
  615. }
  616.  
  617.  
  618. //--------------------------------------------------------------------
  619. // LoadThumbnail
  620. //--------------------------------------------------------------------
  621.  
  622. void LoadThumbnail(Environment* ev, Handle* thumbnail)
  623. {
  624.     if ( *thumbnail ) return;
  625.     
  626.     ODSLong tRef;
  627.     tRef = BeginUsingLibraryResources();
  628.     {
  629.         *thumbnail = (Handle) ::ODLoadPicture(kThumbnailPICT);
  630.     }
  631.     EndUsingLibraryResources(tRef);
  632. }
  633.  
  634. //--------------------------------------------------------------------
  635. // TilePartWindow
  636. //--------------------------------------------------------------------
  637.  
  638. Rect TilePartWindow(Environment* ev, Rect* facetBounds, Rect* partWindowBounds)
  639. {
  640.     const short    kWindowTilingConst    = 20;
  641.     const short kLeftToRight        = 0;
  642.     const short kRightToLeft        = -1;
  643.     
  644.     short direction;
  645.     
  646.     // Get the direction for the primary script system running on this machine.
  647.     // (Right-to-Left or Left-to-Right)
  648.     direction = GetSysDirection();
  649.     
  650.     // The child window should be tiled from the topLeft corner of the 
  651.     // active facet whose frame is being opened.
  652.     if ( direction == kLeftToRight )
  653.     {
  654.         // Position the window rect at the top/left corner of the facet.
  655.         OffsetRect(partWindowBounds, facetBounds->left, facetBounds->top);
  656.         // Now tile the window rect down and to the right.
  657.         OffsetRect(partWindowBounds, kWindowTilingConst, kWindowTilingConst);
  658.     }
  659.     // The child window should be tiled from the topRight corner of the 
  660.     // active facet whose frame is being opened.
  661.     else if ( direction == kRightToLeft )
  662.     {
  663.         // Position the window rect at the top/right corner of the facet.
  664.         OffsetRect(partWindowBounds, (partWindowBounds->right - facetBounds->right),
  665.                     facetBounds->top);
  666.         // Now tile the window rect down and to the left.
  667.         OffsetRect(partWindowBounds, -kWindowTilingConst, kWindowTilingConst);
  668.     }
  669.     
  670.     return *partWindowBounds;
  671. }
  672.  
  673. //--------------------------------------------------------------------
  674. // CountFacets
  675. //--------------------------------------------------------------------
  676.  
  677. ODUShort CountFramesFacets(Environment* ev, ODFrame* frame)
  678. {
  679.     ODUShort facetCount = 0;
  680.     ODFacet* facet;
  681.     
  682.     TempODFrameFacetIterator ffiter(ev, frame);
  683.     facet = ffiter.First();
  684.     while ( ffiter.IsNotComplete() )
  685.     {
  686.         facetCount++;
  687.         facet = ffiter.Next();
  688.     }
  689.     
  690.     return facetCount;
  691. }
  692.  
  693. //=========================================================================
  694. // CCloneInfo
  695. //=========================================================================
  696. CCloneInfo::CCloneInfo(ODDraftKey key, ODDraft* fromDraft,
  697.                         ODFrame* scopeFrame, ODCloneKind kind )
  698. {
  699.     fKey = key;
  700.     fFromDraft  = fromDraft;
  701.     fScopeFrame = scopeFrame;
  702.     fCloneKind = kind; 
  703. }
  704.  
  705.  
  706. CCloneInfo::~CCloneInfo()
  707. {
  708. }
  709.  
  710.  
  711.  
  712. //=========================================================================
  713. // CFrameInfo
  714. //=========================================================================
  715.  
  716. //-------------------------------------------------------------------------
  717. // CFrameInfo::CFrameInfo
  718. //-------------------------------------------------------------------------
  719.  
  720. CFrameInfo::CFrameInfo()
  721. {
  722.     fFrameActive = kODFalse;
  723.     fFrameReactivate  = kODFalse;
  724.     fShouldDisposeWindow = kODFalse;
  725.     fActiveFacet = kODNULL;
  726.     fSourceFrame = kODNULL;
  727.     fAttachedFrame = kODNULL;
  728.     fPartWindow = kODNULL; 
  729. }
  730.  
  731. //-------------------------------------------------------------------------
  732. // CFrameInfo::~CFrameInfo
  733. //-------------------------------------------------------------------------
  734.  
  735. CFrameInfo::~CFrameInfo()
  736. {
  737.     ODSafeReleaseObject(fAttachedFrame);
  738.     ODSafeReleaseObject(fSourceFrame);
  739. }
  740.  
  741. //-------------------------------------------------------------------------
  742. // CFrameInfo::Externalize
  743. //-------------------------------------------------------------------------
  744.  
  745. void CFrameInfo::Externalize(Environment* ev, ODStorageUnitView* storageUnitView)
  746. {
  747.     // This method assumes that OpenDoc has passed us a storageUnitView
  748.     // that is focused to a property, but no particular value.
  749.     
  750.     ODStorageUnit* storageUnit = storageUnitView->GetStorageUnit(ev);
  751.  
  752.     this->CleanseFrameInfoProperty(ev, storageUnit);
  753.     this->ExternalizeFrameInfo(ev, storageUnit, 0, kODNULL);
  754. }
  755.  
  756. //-------------------------------------------------------------------------
  757. // CFrameInfo::CleanseFrameInfoProperty
  758. //-------------------------------------------------------------------------
  759.  
  760. void CFrameInfo::CleanseFrameInfoProperty(Environment* ev, ODStorageUnit* storageUnit)
  761. {
  762.     ODULong numValues;
  763.     ODULong index;
  764.         
  765.     numValues = storageUnit->CountValues(ev);
  766.     
  767.     for (index = numValues; index >= 1; index--)
  768.     {
  769.         // Index, from 1 to n, through the values.
  770.         storageUnit->Focus(ev, kODNULL, kODPosSame, 
  771.                                 kODNULL, index, kODPosUndefined);
  772.                                 
  773.         // Get the ISO type name for the value. The temp object
  774.         // will automatically delete the returned value when this
  775.         // scope is exited.
  776.         TempODValueType value = storageUnit->GetType(ev);
  777.         
  778.         // If the value type is not one we support, remove it.
  779.         if ( ODISOStrCompare(value, kDrawEditorInfo) != 0 )
  780.             storageUnit->Remove(ev);
  781.     }
  782. }
  783.  
  784. //-------------------------------------------------------------------------
  785. // CFrameInfo::ExternalizeFrameInfo
  786. //-------------------------------------------------------------------------
  787.  
  788. void CFrameInfo::ExternalizeFrameInfo(Environment* ev, ODStorageUnit* storageUnit,
  789.                                         ODDraftKey key, ODFrame* scopeFrame)
  790. {
  791.     // This method behaves much the same way as the SamplePart::ExternalizeStateInfo
  792.     // method.
  793.     
  794.     if ( storageUnit->Exists(ev, kODNULL, kDrawEditorInfo, 0) )
  795.     {
  796.         // Persistent object references are stored in a side table, rather than
  797.         // in the property/value stream. Thus, deleting the contents of a value
  798.         // will not "delete" the references previously written to that value. To
  799.         // completely "delete" all references written to the value, we must
  800.         // remove the value and add it back.
  801.  
  802.         storageUnit->Focus(ev, kODNULL, kODPosSame, kDrawEditorInfo, 0 , kODPosUndefined);
  803.         storageUnit->Remove(ev);
  804.     }
  805.     
  806.     if ( fSourceFrame )
  807.     {
  808.         ODStorageUnitRef    weakRef;
  809.         ODID                frameID = fSourceFrame->GetID(ev);
  810.         ODID                scopeFrameID = ( scopeFrame ? scopeFrame->GetID(ev) : kODNULLID );
  811.         ODDraft*            fromDraft = fSourceFrame->GetStorageUnit(ev)->GetDraft(ev);
  812.  
  813.         storageUnit->AddValue(ev, kDrawEditorInfo);
  814.         
  815.         // If a draft key exists, then we are being cloned to another draft.
  816.         // We must "weak" clone our display frame and reference the cloned
  817.         // frame. The part re-uses the frameID variable so there aren't two
  818.         // different GetWeakStorageUnitRef calls.
  819.         if ( key )
  820.             frameID = fromDraft->WeakClone(ev, key, frameID, kODNULLID, scopeFrameID);
  821.         
  822.         // Write out weak references to each of the part's display frames.
  823.         storageUnit->GetWeakStorageUnitRef(ev, frameID, weakRef);
  824.         TRY
  825.             StorageUnitSetValue(storageUnit, ev, sizeof(ODStorageUnitRef), (ODPtr)&weakRef);
  826.         CATCH_ALL
  827.         ENDTRY
  828.     }
  829. }
  830.  
  831. //-------------------------------------------------------------------------
  832. // CFrameInfo::CloneInto
  833. //-------------------------------------------------------------------------
  834.  
  835. void CFrameInfo::CloneInto(Environment *ev, ODDraftKey key,
  836.                             ODStorageUnitView* storageUnitView, ODFrame* scopeFrame)
  837. {
  838.     // This method assumes that OpenDoc has passed us a storageUnitView
  839.     // that is focused to a property, but no particular value.
  840.     
  841.     ODStorageUnit* storageUnit = storageUnitView->GetStorageUnit(ev);
  842.  
  843.     if ( storageUnit->Exists(ev, kODNULL, kDrawEditorInfo, 0) == kODFalse )
  844.     {
  845.         this->ExternalizeFrameInfo(ev, storageUnit, key, scopeFrame);
  846.     }
  847. }
  848.  
  849. //-------------------------------------------------------------------------
  850. // CFrameInfo::InitFromStorage
  851. //------------------------------------------------------------------------------
  852.  
  853. void CFrameInfo::InitFromStorage(Environment* ev, ODStorageUnitView* storageUnitView)
  854. {
  855.     // This method assumes that OpenDoc has passed us a storageUnitView
  856.     // that is focused to a property, but no particular value.
  857.     
  858.     ODStorageUnit* storageUnit = storageUnitView->GetStorageUnit(ev);
  859.  
  860.     if ( storageUnit->Exists(ev, kODNULL, kDrawEditorInfo, 0) )
  861.     {
  862.         TRY
  863.             storageUnit->Focus(ev, kODNULL, kODPosSame,
  864.                                         kDrawEditorInfo, 0 , kODPosUndefined);
  865.     
  866.             ODULong size = storageUnit->GetSize(ev);
  867.         
  868.             // If the frame does not have a source frame, make sure the value
  869.             // is empty.    
  870.             if ( size > 0 )
  871.             {
  872.                 ODStorageUnitRef weakRef;
  873.                 
  874.                 StorageUnitGetValue(storageUnit, ev, sizeof(ODStorageUnitRef),
  875.                                     (ODPtr)&weakRef);
  876.                 
  877.                 if ( storageUnit->IsValidStorageUnitRef(ev, weakRef) )
  878.                 {
  879.                     ODID sourceID = storageUnit->GetIDFromStorageUnitRef(ev, weakRef);
  880.                     ODFrame* frame = storageUnit->GetDraft(ev)->AcquireFrame(ev, sourceID);
  881.                     
  882.                     fSourceFrame = frame;
  883.                 }
  884.                 else
  885.                 {
  886.                     fSourceFrame = kODNULL;
  887.                 }
  888.             }
  889.             
  890.         CATCH_ALL
  891.             fSourceFrame = kODNULL;
  892.         ENDTRY
  893.     }
  894. }
  895.  
  896. //-------------------------------------------------------------------------
  897. // CFrameInfo::SetSourceFrame
  898. //-------------------------------------------------------------------------
  899.  
  900. void CFrameInfo::SetSourceFrame(Environment* ev, ODFrame* sourceFrame)
  901. {
  902.     if ( sourceFrame != kODNULL )
  903.     {
  904.         ODAcquireObject(ev, sourceFrame);
  905.         ODReleaseObject(ev, fSourceFrame);
  906.         fSourceFrame = sourceFrame;
  907.     }
  908. }
  909.  
  910. //-------------------------------------------------------------------------
  911. // CFrameInfo::ReleaseSourceFrame
  912. //-------------------------------------------------------------------------
  913.  
  914. void CFrameInfo::ReleaseSourceFrame(Environment* ev)
  915. {
  916.     ODReleaseObject(ev, fSourceFrame);
  917. }
  918.  
  919. //-------------------------------------------------------------------------
  920. // CFrameInfo::AttachFrame
  921. //-------------------------------------------------------------------------
  922.  
  923. void CFrameInfo::AttachFrame(Environment* ev, ODFrame* frame)
  924. {
  925.     if ( frame != kODNULL )
  926.     {
  927.         ODAcquireObject(ev, frame);
  928.         ODReleaseObject(ev, fAttachedFrame);
  929.         fAttachedFrame = frame;
  930.     }
  931. }
  932.  
  933. //-------------------------------------------------------------------------
  934. // CFrameInfo::DetachFrame
  935. //-------------------------------------------------------------------------
  936.  
  937. void CFrameInfo::DetachFrame(Environment* ev)
  938. {
  939.     ODReleaseObject(ev, fAttachedFrame);
  940. }
  941.  
  942.  
  943.  
  944.